package com.itheima.stock.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    /**
     * 重新定义消息序列化的方式，改为基于json格式序列化和反序列化
     * @return
     */
    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    //交换机--发
  @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("stockExchange",true,false);
  }

  //定义列队--吃
  @Bean
    public Queue innerMarketQueue(){
        return new Queue("innerMarketQueue",true);
  }

  //绑定国内大盘队列
  @Bean
    public Binding  bindingInnerMarkerQueue(){
        return BindingBuilder.bind(innerMarketQueue()).to(topicExchange()).with("inner.market");
  }
}